import { http } from "@/utils/http";

// 获取用餐记录列表（分页+搜索）
export function getDiningList(params: {
  page: number;
  size: number;
  [key: string]: any;
}) {
  return http.get("/love/records", { params });
}

// 新增用餐记录
export function addDining(data: any) {
  return http.post("/love/records", data);
}

// 编辑用餐记录
export function editDining(id: number, data: any) {
  return http.put(`/love/records/${id}`, { data });
}

// 删除用餐记录
export function deleteDining(id: number) {
  return http.delete(`/love/records/${id}`);
}

// 获取单条用餐记录详情
export function getDiningDetail(id: number | string) {
  return http.get(`/love/records/${id}`);
}

export interface RecordImage {
  id: number;
  imageUrl: string;
}

/** 根据日常记录ID获取图片列表 */
export const getImagesByRecordId = (recordId: number) => {
  return http.request<any, RecordImage[]>(
    "get",
    `/love/records/${recordId}/images`
  );
};

// 上传图片（真实接口，支持批量）
export function uploadImage(recordId: number, files: File[]) {
  const formData = new FormData();
  files.forEach(file => formData.append("files", file));
  return http.post(`/love/upload/${recordId}`, formData, {
    headers: { "Content-Type": "multipart/form-data" }
  });
}

/** 删除用餐记录图片 */
export const deleteImage = (imageId: number) => {
  return http.request<any, any>("delete", `/love/images/${imageId}`);
};
